import { result } from 'lodash';
/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-08-12 16:13:24
 * @LastEditors: 商晓彬
 * @LastEditTime: 2022-01-04 14:30:31
 */
import { AfterViewChecked, Component, ElementRef, EventEmitter, Injector, Input, Output, ViewChild } from '@angular/core';
import { AppConsts } from '@shared/AppConsts';
import { AppComponentBase } from '@shared/common/app-component-base';
import {
    MoadifManageServiceProxy, BopUnifyServiceProxy, BopNodeServiceProxy,
    ProcessesEntityDto, WorkStepAndProcessDto, RTechFileHeaderDto, BopContentInfoDto,
    TechContentInput, TechDefendInput, ModifyProcessesDto, QualityControlDto,
    ModifyWorkingStepDto, InsertDetailsDto, ManufacturingResourcesDto, VideoFrequencyDto,
    AssembleDto, GlueSolutionDto, HatchOpenShutDto, InCabinDto, MainPartsDto, MomentRecordingDto,
    MultimediaRecordDto, TorqueReCalibrationDto, CablePlugWaterFireProofDto, BellowsDeformationDto,
    ElectricalConnectInsertionDto, HatchOpenShutTestDto, ProductGroundingStatusDto, ForcedCheckpointDto,
    AutomaticShutoffDto, ServomechanismDto, StatusCheckDto, ProblemRecordDto, SoapBubbleDto, HeliumMassSpectrometryDto,
    DetonatingCableSizeDto, ReleaseSpringCompressionDto, LoadBracketDto, DesignGeneralAssembleDto, FinalAssemblyPartsDto,
    SensorInstallationDto, PlugStatusDto, FirstIMUInstallationDto, SecondIMUInstallationDto, CableHeightDto, LowCrimpingExperimentDto,
    LowFrequencyCableStrippingDto, HighFrequencyCableStrippingDto, InstrumentCheckDto, CableReceivingInspectionDto, ArrowInterfaceProtectCheckDto,
    InspectionRecordDto, DockSurfaceMorphemeDto, FilingFileRepairDto, CheckFairingAfterInstallationDto, CatheterizationDto, BlowPipeArrowDto,
    GasPipeTestDto, ValvesGasInspectionDto, InstallationLocationDto, InstallationDistanceDto, MeasurementSpacingConduitDto, FailureAequiredLoosInsuranceDto,
    DisassemblyReassemblyDto, Insulation703Dto, AdiabaticRemovalDto, CalibrationContinuousTorqueDto, InstallationPipeCushionDto, ArrowStructureWaterproofDto,
    WaterproofInstallationLapdDto, AssemnleweighingDto, GeneralWeighingDto, ArrowWeightDto, ArrowScalageProductsDto, LevelingDataFlightDto, FlightMassCentroidTareWeightDto,
    TransverseCentroidDto, LargeSectionWeightDto, ProductInstallationConfirmationDto, ConfirmationStatusDto, ReceivingInspectionRecordDto, ProtectivePartsDto, InterfaceCheckDto,
    QuadrantCheckDto, DesiccantInspectionDto, LargePartsDeliveryDto, CylinderGroupDto, SystemPressureMaintainingDto, CylinderPressureTestDto, ValveUsageTimesDto, ValveTestDto, GasSealFlowTestDto
    , ValveTestSecDto, TailCoverSolenoidDto, CorrespondingRelationshipDto, InstallationQuantityDto, LiquidLevelSensorDto, CrimpingSealedPlugDto, JobDivisionDto, ExperimentalCrimpingDto, HighFrequencyVoltageDto,
    TensileStrengthHighDto, WorkStepOutDto, GeneralRecordsDto, ImageParm,

} from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import * as _ from 'lodash';
import { finalize } from 'rxjs/operators';
import { TreeNode } from 'primeng/api';
import { MessageService } from '@abp/message/message.service';
import * as moment from 'moment';
import { MountDetailsComponent } from '../mount-details/mount-details.component';
import { ChooseBomComponent } from '../choose-bom/choose-bom.component';
@Component({
    selector: 'maintain',
    templateUrl: './maintain.component.html',
    styleUrls: ['./maintain.component.less']
})
export class MaintainComponent extends AppComponentBase {
    @ViewChild('MountDetailsComponent') MountDetailsComponent: MountDetailsComponent;
    @ViewChild('ChooseBomComponent') ChooseBomComponent: ChooseBomComponent;
    @ViewChild('createOrEditModal') modal: ModalDirective;
    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
    @Input() parentrow: any;//父级节点信息  
    @Input() title: any;//父级节点信息  
    @Input() changeId: any;//父级节点信息  
    active = false;
    saving = false;
    loadingtree = false;
    files2: any;//树形结构
    ischeckTree: any;//选中行
    btInfo: BopContentInfoDto = new BopContentInfoDto();//部套
    btInfoDate = undefined;// 部套新增时间
    btInfoNewDate = undefined;// 部套新增时间
    check = [];// 工序
    processFile: RTechFileHeaderDto = new RTechFileHeaderDto();//工艺规程
    //右侧工序信息
    processInfo: ProcessesEntityDto = new ProcessesEntityDto();
    //右侧工步信息
    workstepInfo: WorkStepAndProcessDto = new WorkStepAndProcessDto();
    workStepHeader: any;//工步动态表Header
    workStepData: any = [];//工步动态表List
    genders = [];// 工部表头下拉内容
    tablemodel = undefined;// 参数
    addTitle = undefined;
    addFlag = false;
    addForm = { materialCode: undefined, workCode: undefined, materialname: undefined };
    stageSignOption = [];
    techniqueTypecOption = [];
    shapeOption = [];
    secretDegreeOption = [];
    leveFlag = false;
    tableShowFlag = false;
    paneName = undefined;
    tableData = undefined;
    paneKye = undefined;
    updateFlag = undefined;
    editFlag = false;
    saveFlag = true;
    photoList = [];//变更图片展示
    uploadedFiles = [];//上传图片
    photoId = undefined;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _moadifManageServiceProxy: MoadifManageServiceProxy,
        private _bopUnifyServiceProxy: BopUnifyServiceProxy,
        private _bopNodeServiceProxy: BopNodeServiceProxy,
    ) {
        super(injector);
    }
    ngOnInit() {
    }
    //打开弹窗
    onShown(): void {
        this.getTreeDate(false);
        this.getNodeDesc();
        this._bopNodeServiceProxy.loadTableName()
            .pipe(finalize(() => { })).subscribe(result => {
                this.genders = [];
                result.forEach(item => {
                    this.genders.push({
                        label: item,
                        value: item
                    })
                });
                this.tablemodel = this.genders[0].value;
            });
        this._moadifManageServiceProxy.getEnumDescs(1).
            pipe(finalize(() => { })).subscribe(result => {
                this.stageSignOption = [
                    {
                        label: '请选择',
                        value: undefined
                    }
                ];
                for (const item of result) {
                    this.stageSignOption.push(item);
                }
            });
        this._moadifManageServiceProxy.getEnumDescs(2).
            pipe(finalize(() => { })).subscribe(result => {
                this.techniqueTypecOption = [
                    {
                        label: '请选择',
                        value: undefined
                    }
                ];
                for (const item of result) {
                    this.techniqueTypecOption.push(item);
                }
            });
        this._moadifManageServiceProxy.getEnumDescs(3).
            pipe(finalize(() => { })).subscribe(result => {
                this.shapeOption = [
                    {
                        label: '请选择',
                        value: undefined
                    }
                ];
                for (const item of result) {
                    this.shapeOption.push(item);
                }
            });
        this._moadifManageServiceProxy.getEnumDescs(4).
            pipe(finalize(() => { })).subscribe(result => {
                this.secretDegreeOption = [
                    {
                        label: '请选择',
                        value: undefined
                    }
                ];
                for (const item of result) {
                    this.secretDegreeOption.push(item);
                }
            });
    }
    show(): void {
        this.active = true;
        this.modal.show();
    }
    expandAll() {
        this.files2.forEach((node) => {
            this.expandRecursive(node, true);
        });
    }
    collapseAll() {
        this.files2.forEach((node) => {
            this.expandRecursive(node, false);
        });
    }
    exdents(oldNode) {
        for (let i = 0; i < this.files2.length; i++) {
            if (this.files2[i].id == oldNode[i].id) {
                this.exdentsNode(oldNode[i], this.files2[i]);
            }

        }
    }
    private expandRecursive(node: TreeNode, isExpand: boolean) {
        node.expanded = isExpand;
        if (node.children) {
            node.children.forEach((childNode) => {
                this.expandRecursive(childNode, isExpand);
            });
        }
    }
    private exdentsNode(oldNode, newNode) {
        if (oldNode != undefined) {
            if (oldNode.id == newNode.id) {
                newNode.expanded = oldNode.expanded;
                if (newNode.children) {
                    for (let i = 0; i < newNode.children.length; i++) {
                        this.exdentsNode(oldNode.children[i], newNode.children[i]);
                    }
                }
            }
        }
    }
    close(): void {
        this.saveFlag = true;
        this.active = false;
        this.modalSave.emit(this.changeId);
        this.modal.hide();
    }
    getBtinfo(id) {
        this._moadifManageServiceProxy.getMoadifManageInfoById(id)
            .pipe(finalize(() => { }))
            .subscribe(result => {
                this.btInfo = result;
                this.btInfoDate = moment(result.relationDate).format('YYYY-MM-DD HH:mm:ss');
                this.btInfoNewDate = moment(result.exportDate).format('YYYY-MM-DD HH:mm:ss');
            });
    }
    getProcessInfo(id) {
        this.check = [];
        this._bopNodeServiceProxy.getProcessesById(id)
            .pipe(finalize(() => { })).subscribe(result => {
                this.processInfo = result;
                if (this.processInfo.processesCharacteristic) {
                    let item = this.processInfo.processesCharacteristic.split('|');
                    this.check = item;
                    this.check.splice(this.check.length - 1, 1);
                }

            })
    }
    getWorkStepInfo(id) {
        this._bopNodeServiceProxy.getWorkStepOut(id)
            .pipe(finalize(() => { }))
            .subscribe(result => {
                this.workstepInfo = result;
                // abp.ui.clearBusy();
                if (Object.keys(result.tableNameDictionary).length != 0) {
                    this.paneKye = this.workstepInfo.tableNameDictionary[0].tablekey;
                    this.paneName = this.workstepInfo.tableNameDictionary[0].tableName;
                    this.workStepHeader = this.workstepInfo.tableNameDictionary[0];
                    this.workStepData = this.workstepInfo.workStepOut[this.workstepInfo.tableNameDictionary[0].tablekey];
                    // this.onTabChange({ index: 0 });
                }
            });
    }
    saveWorkStepInfo(index) {
        this._bopNodeServiceProxy.getWorkStepOut(this.ischeckTree.id)
            .pipe(finalize(() => { }))
            .subscribe(result => {
                if (Object.keys(result.tableNameDictionary).length != 0) {
                    this.paneKye = this.workstepInfo.tableNameDictionary[index].tablekey;
                    this.paneName = this.workstepInfo.tableNameDictionary[index].tableName;
                    this.workStepHeader = this.workstepInfo.tableNameDictionary[index];
                    this.workStepData = this.workstepInfo.workStepOut[this.workstepInfo.tableNameDictionary[index].tablekey];
                }
            });
    }
    nodeSelect(event) {
        this.ischeckTree = event.node;
        this.workStepData = [];
        if (parseInt(this.ischeckTree.nodeLevel) == 8) {
            //工序
            this.leveFlag = true;
        } else {
            //工步或父级
            this.leveFlag = false;
        }
        if (parseInt(this.ischeckTree.nodeLevel) == 8) {
            this.updateFlag = true;
        } else if (parseInt(this.ischeckTree.nodeLevel) == 9) {
            this.updateFlag = false;
        }
        //父节点
        if (parseInt(this.ischeckTree.nodeLevel) != 8 && parseInt(this.ischeckTree.nodeLevel) != 9) {
            this.getBtinfo(event.node.id);
        }
        //工序
        if (parseInt(this.ischeckTree.nodeLevel) == 8) {
            this.getProcessInfo(event.node.id);
        }
        //工部
        if (parseInt(this.ischeckTree.nodeLevel) == 9) {
            this.getWorkStepInfo(event.node.id);
            this._bopNodeServiceProxy.getImageParms(event.node.id)
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.photoList = result;
                    for (let i = 0; i < this.photoList.length; i++) {
                        const item = this.photoList[i];
                        item.pName = item.name;
                        let names = item.src.split('/');
                        item.name = names[names.length - 1];
                        item.id = i + 1;
                        if (i + 1 == this.photoList.length) {
                            this.photoId = i + 1;
                        }
                    }
                    if (result.length == 0) {
                        this.photoId = 0;
                    }
                });
        }
    }
    myUploader(event, index) {
        let files = [];
        for (const item of event.files) {
            let data = { data: item, fileName: item.name };
            files.push(data);
        }
        if (this.saveFlag) {
            this.saveFlag = false;
            this._bopNodeServiceProxy.onPostUploadAsync(
                files,
                this.ischeckTree.id
            )
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.saveFlag = true;
                    if (result.code == 0) {
                        let rsFiles = [];
                        for (let i = 0; i < files.length; i++) {
                            let item = files[i];
                            let data = { src: undefined, name: undefined, files: undefined, id: undefined, pName: undefined };
                            data.src = result.data[i];
                            data.files = item.data;
                            data.id = this.photoId + 1;
                            data.name = item.fileName;
                            this.photoId++;
                            let name = item.fileName.split('.');
                            if (name.length > 2) {
                                //说明名称带点
                                for (let i = 0; i < name.length; i++) {
                                    if (i + 1 != name.length) {
                                        const item = name[i];
                                        data.pName = data.name + item;
                                    }
                                }
                            } else {
                                data.pName = name[0];
                            }
                            rsFiles.push(data);
                        }
                        for (const item of rsFiles) {
                            this.photoList.splice(index + 1, 0, item);
                        }
                        this.uploadedFiles = [];
                    } else {
                        this._messageService.error(result.message);
                    }
                });
        }
    }
    savePhoto() {
        let input = [];
        let files = [];
        for (const item of this.photoList) {
            let data = { id: undefined, fileName: undefined, pname: undefined };
            data.id = item.id;
            data.fileName = item.pName;
            data.pname = item.pName;
            if (item.files) {
                let data = { data: item.files, fileName: item.name };
                files.push(data);
            }
            input.push(data);
        };
        if (this.saveFlag) {
            this.saveFlag = false;
            this._bopNodeServiceProxy.saveUploadPic(
                files,
                JSON.stringify(input),
                this.ischeckTree.id
            )
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.saveFlag = true;
                    if (result.code == 1) {
                        this._messageService.error(result.message)
                    } else {
                        this._messageService.success('保存成功');
                        this.photoList = []
                        this._bopNodeServiceProxy.getImageParms( this.ischeckTree.id)
                            .pipe(finalize(() => { }))
                            .subscribe(result => {
                                this.photoList = result;
                                for (let i = 0; i < this.photoList.length; i++) {
                                    const item = this.photoList[i];
                                    item.pName = item.name;
                                    let names = item.src.split('/');
                                    item.name = names[names.length - 1];
                                    item.id = i + 1;
                                    if (i + 1 == this.photoList.length) {
                                        this.photoId = i + 1;
                                    }
                                }
                                if (result.length == 0) {
                                    this.photoId = 0;
                                }
                            });
                    }
                });
        }

    }
    photoDel(index) {
        this.photoList.splice(index, 1);
    }
    //tab 切换工步动态表
    onTabChange(event) {
        this.message.confirm(
            '是否保存当前表格数据然后切换到其他表格？',
            (isConfirmed) => {
                if (isConfirmed) {
                    let workStep = new WorkStepOutDto();
                    workStep.id = this.workstepInfo.workStepOut.id;
                    workStep.processesEntityId = this.ischeckTree.id;
                    for (let i = 0; i < this.workStepData.length; i++) {
                        this.workStepData[i].sort = i;
                    }
                    workStep[this.paneKye] = this.workStepData;
                    if (this.saveFlag) {
                        this.saveFlag = false;
                        this._moadifManageServiceProxy.insertOrUpdateMoadifTable(
                            workStep,
                            this.paneName,
                            this.changeId
                        )
                            .pipe(finalize(() => { }))
                            .subscribe(result => {
                                this.saveFlag = true;
                                if (result.code == 0) {
                                    this._messageService.success('修改成功');
                                    this.saveWorkStepInfo(event.index);
                                } else {
                                    this._messageService.error(result.message)
                                }
                            });
                    }
                } else {
                    this.paneKye = this.workstepInfo.tableNameDictionary[event.index].tablekey;
                    this.paneName = this.workstepInfo.tableNameDictionary[event.index].tableName;
                    this.workStepHeader = this.workstepInfo.tableNameDictionary[event.index];
                    this.workStepData = this.workstepInfo.workStepOut[this.workstepInfo.tableNameDictionary[event.index].tablekey];
                }
            }
        );

    }
    getTreeDate(value) {
        this.loadingtree = true;
        this._moadifManageServiceProxy.spanningTechTree(this.parentrow.id)
            .pipe(finalize(() => { }))
            .subscribe(result => {
                if (!value) {
                    this.files2 = [];
                    this.files2[0] = result;
                    this.expandAll();
                }
                if (value) {
                    let oldNode = [...this.files2];
                    this.files2 = [];
                    this.files2.push(result);
                    this.exdents(oldNode);
                }
                this.ischeckTree = {};
                this.loadingtree = false;
            });
    }
    getNodeDesc() {
        this._bopUnifyServiceProxy.getTechFileHeader(this.parentrow.id)
            .pipe(finalize(() => { }))
            .subscribe(result => {
                this.processFile = result;
            });
    }
    insertBopTree(type) {
        this.addForm.materialCode = undefined;
        this.addForm.materialname = undefined;
        this.addForm.workCode = undefined;
        if (Object.keys(this.ischeckTree).length == 0) {
            this._messageService.info('请选择一个节点');
            return;
        }

        if (type) {
            //新增
            if (parseInt(this.ischeckTree.nodeLevel) == 9) {
                this._messageService.info('该节点下不能新增');
                return;
            }
            this.addTitle = '新增';
            this.addFlag = true;

        } else {
            if (parseInt(this.ischeckTree.nodeLevel) != 9 && parseInt(this.ischeckTree.nodeLevel) != 8) {
                this._messageService.info("父节点不可修改");
                return;
            }
            //修改
            this.addTitle = '修改';
            let mater = undefined;
            let work = undefined;
            if (this.updateFlag) {
                let data = this.ischeckTree.nodeDrawingNo.split('工序');
                mater = parseInt(data[1]);
            } else {
                // let data = this.ischeckTree.nodeDrawingNo.split('工步');
                work = this.ischeckTree.nodeName;
            }
            this.addForm.materialCode = mater;
            this.addForm.workCode = work;
            this.addForm.materialname = this.ischeckTree.nodeName;
            this.editFlag = true;
        }
    }
    deleteItem() {
        //删除
        if (Object.keys(this.ischeckTree.children).length > 0) {
            this._messageService.info('请先删除子节点');
            return;
        }
        if (Object.keys(this.ischeckTree).length == 0) {
            this._messageService.info('请选择一个节点');
            return;
        }
        if (parseInt(this.ischeckTree.nodeLevel) != 9 && parseInt(this.ischeckTree.nodeLevel) != 8) {
            this._messageService.info('父节点不可删除');
            return;
        }
        this.message.confirm(
            '确认删除' + this.ischeckTree.nodeName + '吗',
            (isConfirmed) => {
                if (isConfirmed) {
                    if (this.saveFlag) {
                        this.saveFlag = false;
                        if (this.updateFlag) {
                            this._moadifManageServiceProxy
                                .deletdProcessById(this.ischeckTree.id)
                                .subscribe((result) => {
                                    this.saveFlag = true;
                                    if (result.code == 0) {
                                        this.getTreeDate(true);
                                        this._messageService.success('删除成功');
                                    } else {
                                        this._messageService.error(result.message)
                                    }

                                });
                        } else {
                            this._moadifManageServiceProxy
                                .deletdWorkStepById(this.ischeckTree.id)
                                .subscribe((result) => {
                                    this.saveFlag = true;
                                    if (result.code == 0) {
                                        this.getTreeDate(true);
                                        this._messageService.success('删除成功');
                                    } else {
                                        this._messageService.error(result.message)
                                    }
                                });
                        }
                    }
                }
            }
        );
    }
    saveText() {
        let input = new TechContentInput();
        input.techniqueExplain = this.btInfo.techniqueExplain;
        input.techId = this.ischeckTree.id;
        if (this.saveFlag) {
            this.saveFlag = false;
            this._moadifManageServiceProxy.defendTechniqueExplain(
                input
            )
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.saveFlag = true;
                    if (result.code == 0) {
                        this._messageService.success('保存成功');
                        this.getBtinfo(this.ischeckTree.id);
                    } else {
                        this._messageService.error(result.message)
                    }

                });
        }

    }
    saveGui() {
        let input = new TechDefendInput();
        input.id = this.ischeckTree.id;
        input.techniqueNumber = this.processFile.techniqueNumber;
        input.techniqueName = this.processFile.techniqueName;
        input.systemCode = this.processFile.systemCode;
        input.productCode = this.processFile.productCode;
        input.moduleCode = this.processFile.moduleCode;
        input.moduleName = this.processFile.moduleName;
        input.stageSign = this.processFile.stageSign;
        input.techniqueType = this.processFile.techniqueType;
        input.techniqueCharacter = this.processFile.techniqueCharacter;
        input.shape = this.processFile.shape;
        input.secretDegree = this.processFile.secretDegree;
        input.useUnit = this.processFile.useUnit;
        input.useTime = this.processFile.useTime;
        input.basisFile = this.processFile.basisFile;
        input.issueUnit = this.processFile.issueUnit;
        input.remark = this.processFile.remark;
        if (this.saveFlag) {
            this.saveFlag = false;
            this._moadifManageServiceProxy.defendTechnique(
                input
            )
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.saveFlag = true;
                    if (result.code == 0) {
                        this._messageService.success('保存成功');
                        this.getNodeDesc();
                    } else {
                        this._messageService.error(result.message)
                    }

                });
        }
    }
    saveMiao() {
        let input = new TechContentInput();
        input.nodeDrawingNo = this.btInfo.nodeDrawingNo;
        input.nodeName = this.btInfo.nodeName;
        input.techId = this.ischeckTree.id;
        if (this.saveFlag) {
            this.saveFlag = false;
            this._moadifManageServiceProxy.defendTechniqueNode(
                input
            )
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.saveFlag = true;
                    if (result.code == 0) {
                        this._messageService.success('保存成功');
                        this.getBtinfo(this.ischeckTree.id);
                    } else {
                        this._messageService.error(result.message)
                    }

                });
        }
    }
    saveXu() {
        let input = new ModifyProcessesDto();
        input.id = this.ischeckTree.id;
        input.techniqueEntityId = this.files2[0].id;
        input.processesSequence = this.processInfo.processesSequence;
        input.processesExplain = this.processInfo.processesExplain;
        input.processesName = this.ischeckTree.nodeName;
        if (this.saveFlag) {
            this.saveFlag = false;
            this._moadifManageServiceProxy.insertOrUpdateProcesses(
                input
            )
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    this.saveFlag = true;
                    if (result.code == 0) {
                        this._messageService.success('修改成功');
                        this.getProcessInfo(this.ischeckTree.id);
                    } else {
                        this._messageService.error(result.message)
                    }
                });
        }
    }
    saveBu() {
        //工步信息提交
        let input = new ModifyWorkingStepDto();
        input.techniqueEntityId = this.files2[0].id;
        input.processesEntityId = this.ischeckTree.parentId;
        input.workDetails = this.workstepInfo.workStepOut.workDetails;
        input.id = this.ischeckTree.id;
        input.workStepNumber = parseInt(this.ischeckTree.nodeName);
        if (this.saveFlag) {
            this.saveFlag = false;
            this._moadifManageServiceProxy.insertOrUpdateWorkingStep(
                input
            )
                .pipe(finalize(() => { }))
                .subscribe(result => {
                    // 表格提交
                    let workStep = new WorkStepOutDto();
                    workStep.id = this.workstepInfo.workStepOut.id;
                    workStep.processesEntityId = this.ischeckTree.id;
                    for (let i = 0; i < this.workStepData.length; i++) {
                        this.workStepData[i].sort = i + 1;
                    }
                    workStep[this.paneKye] = this.workStepData;
                    this._moadifManageServiceProxy.insertOrUpdateMoadifTable(
                        workStep,
                        this.paneName,
                        this.changeId
                    )
                        .pipe(finalize(() => { }))
                        .subscribe(result => {
                            this.saveFlag = true;
                            if (result.code == 0) {
                                this._messageService.success('修改成功');
                                this.getWorkStepInfo(this.ischeckTree.id);
                            } else {
                                this._messageService.error(result.message)
                            }
                        });
                });
        }
    }
    handleClose(event) {
        if (this.workstepInfo.tableNameDictionary.length != 1) {
            this.message.confirm(
                '确认删除' + this.workstepInfo.tableNameDictionary[event.index].tableName + '吗?删除后数据不可恢复！',
                (isConfirmed) => {
                    if (isConfirmed) {
                        if (this.saveFlag) {
                            this.saveFlag = false;
                            this._bopNodeServiceProxy.deleteWorkTable(
                                this.ischeckTree.id,
                                this.workstepInfo.tableNameDictionary[event.index].tableName
                            )
                                .pipe(finalize(() => { }))
                                .subscribe(result => {
                                    this.saveFlag = true;
                                    if (result.code == 0) {
                                        this._messageService.success('删除成功');
                                        this.paneKye = this.workstepInfo.tableNameDictionary[0].tablekey;
                                        this.paneName = this.workstepInfo.tableNameDictionary[0].tableName;
                                        this.workStepHeader = this.workstepInfo.tableNameDictionary[0];
                                        this.workStepData = this.workstepInfo.workStepOut[this.workstepInfo.tableNameDictionary[0].tablekey];
                                        // this.onTabChange({ index: 0 });
                                        this.workstepInfo.tableNameDictionary.splice(event.index, 1);
                                        event.close();
                                    } else {
                                        this._messageService.error(result.message)
                                    }
                                });
                        }
                    }
                }
            );
        } else {
            this._messageService.error('至少保留一个表');
        }
    }
    addBu() {
        this._bopNodeServiceProxy.getTableDetails(
            this.tablemodel
        )
            .pipe(finalize(() => { }))
            .subscribe(result => {
                for (const item of this.workstepInfo.tableNameDictionary) {
                    if (item.tablekey == result.tablekey) {
                        this._messageService.info("表中已存在" + result.tableName + "不可以重复添加");
                        return;
                    }
                }
                this.workstepInfo.tableNameDictionary.push(result);
                this.switchDto(result.tableName);
                let guids = [];
                for (let i = 0; i < 8; i++) {
                    let guid = (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
                    guids.push(guid);
                }
                let guidCode = guids[0] + guids[1] + "-" + guids[2] + "-" + guids[3] + "-" + guids[4] + "-" + guids[5] + guids[6] + guids[7];
                this.tableData.id = guidCode;
                if (this.workstepInfo.workStepOut[result.tablekey] == null) {
                    this.workstepInfo.workStepOut[result.tablekey] = [];
                    this.workstepInfo.workStepOut[result.tablekey].push(this.tableData);
                } else {
                    this.workstepInfo.workStepOut[result.tablekey].push(this.tableData);
                }
                if (this.workstepInfo.tableNameDictionary.length == 1) {
                    // this.onTabChange({ index: 0 });
                    this.paneKye = this.workstepInfo.tableNameDictionary[0].tablekey;
                    this.paneName = this.workstepInfo.tableNameDictionary[0].tableName;
                    this.workStepHeader = this.workstepInfo.tableNameDictionary[0];
                    this.workStepData = this.workstepInfo.workStepOut[this.workstepInfo.tableNameDictionary[0].tablekey];
                }
                if (this.workstepInfo.tableNameDictionary.length != 0) {
                    this.tableShowFlag = false;
                }
            });
        this.tableShowFlag = false;
    }
    addTree(type) {
        if (type == 1) {
            //工序
            let input = new ModifyProcessesDto();
            input.techniqueEntityId = this.files2[0].id;
            input.processesName = this.addForm.materialname;
            if (this.addForm.materialCode <= 0) {
                this._messageService.info('工序序号必须大于0');
                return;
            }
            input.processesSequence = this.addForm.materialCode;
            if (this.saveFlag) {
                this.saveFlag = false;
                //添加节点
                this._moadifManageServiceProxy.insertOrUpdateProcesses(
                    input
                )
                    .pipe(finalize(() => { }))
                    .subscribe(result => {
                        this.saveFlag = true;
                        if (result.code == 0) {
                            this.getTreeDate(true);
                            this._messageService.success('添加成功');
                            this.addFlag = false;
                            this.addForm.materialCode = undefined;
                            this.addForm.materialname = undefined;
                            this.addForm.workCode = undefined;
                        } else {
                            this._messageService.error(result.message)
                        }
                    });
            }
        } else {
            //工步
            let input = new ModifyWorkingStepDto();
            input.techniqueEntityId = this.files2[0].id;
            input.processesEntityId = this.ischeckTree.id;
            input.workStepName = '';
            if (this.addForm.workCode <= 0) {
                this._messageService.info('工步序号必须大于0');
                return;
            }
            input.workStepNumber = this.addForm.workCode;
            if (this.saveFlag) {
                this.saveFlag = false;
                this._moadifManageServiceProxy.insertOrUpdateWorkingStep(
                    input
                )
                    .pipe(finalize(() => { }))
                    .subscribe(result => {
                        this.saveFlag = true;
                        if (result.code == 0) {
                            this.getTreeDate(true);
                            this._messageService.success('添加成功');
                            this.addFlag = false;
                            this.addForm.materialCode = undefined;
                            this.addForm.materialname = undefined;
                            this.addForm.workCode = undefined;
                        } else {
                            this._messageService.error(result.message)
                        }
                    });
            }
        }
    }
    editTree(type) {
        if (type == 1) {
            //工序
            let input = new ModifyProcessesDto();
            if (this.addTitle == '修改') {
                input.id = this.ischeckTree.id;
            }
            if (this.addForm.materialCode <= 0) {
                this._messageService.info('工序序号必须大于0');
                return;
            }
            input.techniqueEntityId = this.files2[0].id;
            input.processesName = this.addForm.materialname;
            input.processesSequence = this.addForm.materialCode;
            if (this.saveFlag) {
                this.saveFlag = false;
                //添加节点
                this._moadifManageServiceProxy.insertOrUpdateProcesses(
                    input
                )
                    .pipe(finalize(() => { }))
                    .subscribe(result => {
                        this.saveFlag = true;
                        if (result.code == 0) {
                            this.getTreeDate(true);
                            this._messageService.success('操作成功');
                            this.editFlag = false;
                            this.addForm.materialCode = undefined;
                            this.addForm.materialname = undefined;
                            this.addForm.workCode = undefined;
                        } else {
                            this._messageService.error(result.message)
                        }
                    });
            }

        } else {
            //工步
            let input = new ModifyWorkingStepDto();
            if (this.addTitle == '修改') {
                input.id = this.ischeckTree.id;
            }
            if (this.addForm.workCode <= 0) {
                this._messageService.info('工步序号必须大于0');
                return;
            }
            input.techniqueEntityId = this.files2[0].id;
            input.processesEntityId = this.ischeckTree.id;
            input.workStepName = this.addForm.materialname;
            input.workStepNumber = this.addForm.workCode;
            if (this.saveFlag) {
                this.saveFlag = false;
                this._moadifManageServiceProxy.insertOrUpdateWorkingStep(
                    input
                )
                    .pipe(finalize(() => { }))
                    .subscribe(result => {
                        this.saveFlag = true;
                        if (result.code == 0) {
                            this.getTreeDate(true);
                            this._messageService.success('操作成功');
                            this.editFlag = false;
                            this.addForm.materialCode = undefined;
                            this.addForm.materialname = undefined;
                            this.addForm.workCode = undefined;
                        } else {
                            this._messageService.error(result.message)
                        }
                    });
            }
        }
    }
    tableDelete(row, index) {
        this.workStepData.splice(index, 1);
    }
    tableAdd(row, index, type) {
        if (this.paneName == '装入件明细') {
            if (type == 2) {
                //装入件
                this.MountDetailsComponent.show();
            } else {
                // BOM
                this.ChooseBomComponent.show();
            }
        } else {
            this.switchDto(this.paneName);
            let guids = [];
            for (let i = 0; i < 8; i++) {
                let guid = (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
                guids.push(guid);
            }
            let guidCode = guids[0] + guids[1] + "-" + guids[2] + "-" + guids[3] + "-" + guids[4] + "-" + guids[5] + guids[6] + guids[7];
            this.tableData.id = guidCode;
            this.workStepData.splice(index + 1, 0, this.tableData);
        }
    }
    backToMount(row) {
        if (this.workStepData.length == 1 && this.workStepData[0].sort == undefined) {
            this.workStepData = [];
            this.workStepData = row;
        } else {
            for (const item of row) {
                this.workStepData.push(item);
            }
        }
    }
    switchDto(name) {
        switch (name) {
            case '装入件明细':
                this.tableData = new InsertDetailsDto();
                break;
            case '制造资源':
                this.tableData = new ManufacturingResourcesDto();
                break;
            case '视频':
                this.tableData = new VideoFrequencyDto();
                break;
            case '通用总装数据记录表':
                this.tableData = new AssembleDto();
                break;
            case '胶液配比情况记录表':
                this.tableData = new GlueSolutionDto();
                break;
            case '舱口盖开闭记录表':
                this.tableData = new HatchOpenShutDto();
                break;
            case '进箱舱登记表':
                this.tableData = new InCabinDto();
                break;
            case '具有证明书的主要零件记录表':
                this.tableData = new MainPartsDto();
                break;
            case '力矩记录表':
                this.tableData = new MomentRecordingDto();
                break;
            case '通用多媒体记录表':
                this.tableData = new MultimediaRecordDto();
                break;
            case '通用力矩复校记录表':
                this.tableData = new TorqueReCalibrationDto();
                break;
            case '质量控制记录表':
                this.tableData = new QualityControlDto();
                break;
            case '电缆插头防水防热记录表':
                this.tableData = new CablePlugWaterFireProofDto();
                break;
            case '波纹管变形记录表':
                this.tableData = new BellowsDeformationDto();
                break;
            case '电连接器插接记录表':
                this.tableData = new ElectricalConnectInsertionDto();
                break;
            case '舱口盖开闭测试记录表':
                this.tableData = new HatchOpenShutTestDto();
                break;
            case '产品接地状态检查记录表':
                this.tableData = new ProductGroundingStatusDto();
                break;
            case '强制检验点记录表':
                this.tableData = new ForcedCheckpointDto();
                break;
            case '自动关闭口盖检查记录表':
                this.tableData = new AutomaticShutoffDto();
                break;
            case '伺服机构工艺拉杆长度记录表':
                this.tableData = new ServomechanismDto();
                break;
            case '状态检查表':
                this.tableData = new StatusCheckDto();
                break;
            case '问题记录表':
                this.tableData = new ProblemRecordDto();
                break;
            case '爆索尺寸测量记录表':
                this.tableData = new DetonatingCableSizeDto();
                break;
            case '整流罩星箭分离弹簧压缩数据记录表':
                this.tableData = new ReleaseSpringCompressionDto();
                break;
            case '载荷支架组合体形位数据记录表':
                this.tableData = new LoadBracketDto();
                break;
            case '设计签署总装数据记录表':
                this.tableData = new DesignGeneralAssembleDto();
                break;
            case '管路活门气密点检查记录表皂泡法':
                this.tableData = new SoapBubbleDto();
                break;
            case '管路活门气密点检查记录表氦质谱法':
                this.tableData = new HeliumMassSpectrometryDto();
                break;
            case '除了打保险防松外的总装直属件记录表':
                this.tableData = new FinalAssemblyPartsDto();
                break;
            case '传感器安装测试记录情况统计记录表':
                this.tableData = new SensorInstallationDto();
                break;
            case '插头状态检查表':
                this.tableData = new PlugStatusDto();
                break;
            case '惯组安装记录表一':
                this.tableData = new FirstIMUInstallationDto();
                break;
            case '惯组安装记录表二':
                this.tableData = new SecondIMUInstallationDto();
                break;
            case '电缆高度测量记录表':
                this.tableData = new CableHeightDto();
                break;
            case '电缆剥线试验记录表低频':
                this.tableData = new LowFrequencyCableStrippingDto();
                break;
            case '压接实验测量记录表低频':
                this.tableData = new LowCrimpingExperimentDto();
                break;
            case '电缆剥线试验记录表高频':
                this.tableData = new HighFrequencyCableStrippingDto();
                break;
            case '仪器接收检查记录表':
                this.tableData = new InstrumentCheckDto();
                break;
            case '电缆接收检查记录表':
                this.tableData = new CableReceivingInspectionDto();
                break;
            case '箭地接口保护件检查记录表':
                this.tableData = new ArrowInterfaceProtectCheckDto();
                break;
            case '通用检查记录表':
                this.tableData = new InspectionRecordDto();
                break;
            case '对接面形位记录表':
                this.tableData = new DockSurfaceMorphemeDto();
                break;
            case '整流罩锉修记录表':
                this.tableData = new FilingFileRepairDto();
                break;
            case '整流罩安装后检查记录表':
                this.tableData = new CheckFairingAfterInstallationDto();
                break;
            case '导管检查记录表':
                this.tableData = new CatheterizationDto();
                break;
            case '管路上箭前吹除记录表':
                this.tableData = new BlowPipeArrowDto();
                break;
            case '气封管流量测试记录表':
                this.tableData = new GasPipeTestDto();
                break;
            case '阀门气瓶过滤器流量计输送管金属软管等检查记录表':
                this.tableData = new ValvesGasInspectionDto();
                break;
            case '单机安装位置记录表':
                this.tableData = new InstallationLocationDto();
                break;
            case '安装距离记录表':
                this.tableData = new InstallationDistanceDto();
                break;
            case '小导管卡箍间距测量表':
                this.tableData = new MeasurementSpacingConduitDto();
                break;
            case '未按要求施加力矩及未打保险防松记录表':
                this.tableData = new FailureAequiredLoosInsuranceDto();
                break;
            case '分解重装记录表':
                this.tableData = new DisassemblyReassemblyDto();
                break;
            case '配合七零三绝热记录表':
                this.tableData = new Insulation703Dto();
                break;
            case '绝热去除记录表':
                this.tableData = new AdiabaticRemovalDto();
                break;
            case '连续拧紧环节力矩复校记录表':
                this.tableData = new CalibrationContinuousTorqueDto();
                break;
            case '管路垫块安装情况记录表':
                this.tableData = new InstallationPipeCushionDto();
                break;
            case '箭体结构防水记录表':
                this.tableData = new ArrowStructureWaterproofDto();
                break;
            case '搭接线安装部位防水记录表':
                this.tableData = new WaterproofInstallationLapdDto();
                break;
            case '总装零件称重记录表':
                this.tableData = new AssemnleweighingDto();
                break;
            case '总装耗材称重记录表':
                this.tableData = new GeneralWeighingDto();
                break;
            case '箭体称重记录表':
                this.tableData = new ArrowWeightDto();
                break;
            case '箭体称重时多装少装产品记录表':
                this.tableData = new ArrowScalageProductsDto();
                break;
            case '飞行质量质心设备调平数据记录表':
                this.tableData = new LevelingDataFlightDto();
                break;
            case '飞行质量质心皮重及参数记录表':
                this.tableData = new FlightMassCentroidTareWeightDto();
                break;
            case '横向质心测量记录表':
                this.tableData = new TransverseCentroidDto();
                break;
            case '大部段称重记录表':
                this.tableData = new LargeSectionWeightDto();
                break;
            case '产品安装确认表':
                this.tableData = new ProductInstallationConfirmationDto();
                break;
            case '阀门安装状态确认表':
                this.tableData = new ConfirmationStatusDto();
                break;
            case '通用接收检查记录表':
                this.tableData = new ReceivingInspectionRecordDto();
                break;
            case '通用保护件检查记录表':
                this.tableData = new ProtectivePartsDto();
                break;
            case '接口检查记录表':
                this.tableData = new InterfaceCheckDto();
                break;
            case '象限标识检查记录表':
                this.tableData = new QuadrantCheckDto();
                break;
            case '干燥剂检查记录表':
                this.tableData = new DesiccantInspectionDto();
                break;
            case '随大部段交付产品明细表':
                this.tableData = new LargePartsDeliveryDto();
                break;
            case '气瓶组充放气速率记录表':
                this.tableData = new CylinderGroupDto();
                break;
            case '系统保压记录表':
                this.tableData = new SystemPressureMaintainingDto();
                break;
            case '气瓶压力测试记录表':
                this.tableData = new CylinderPressureTestDto();
                break;
            case '阀门使用次数记录表':
                this.tableData = new ValveUsageTimesDto();
                break;
            case '阀门测试记录表一':
                this.tableData = new ValveTestDto();
                break;
            case '气封流量测试记录表':
                this.tableData = new GasSealFlowTestDto();
                break;
            case '阀门测试记录表二':
                this.tableData = new ValveTestSecDto();
                break;
            case '电磁阀尾罩检查表':
                this.tableData = new TailCoverSolenoidDto();
                break;
            case '传感器变换器对应关系确认记录表':
                this.tableData = new CorrespondingRelationshipDto();
                break;
            case '产品安装数量记录表':
                this.tableData = new InstallationQuantityDto();
                break;
            case '液位传感器尺寸协调记录表':
                this.tableData = new LiquidLevelSensorDto();
                break;
            case '密封插头压接多媒体记录表':
                this.tableData = new CrimpingSealedPlugDto();
                break;
            case '岗位分工表':
                this.tableData = new JobDivisionDto();
                break;
            case '低频压接实验测量记录表':
                this.tableData = new ExperimentalCrimpingDto();
                break;
            case '高频压接点电阻及抗电强度检查记录表':
                this.tableData = new HighFrequencyVoltageDto();
                break;
            case '高频压接点抗拉强度检查记录表':
                this.tableData = new TensileStrengthHighDto();
                break;
            case '通用记录表':
                this.tableData = new GeneralRecordsDto();
                break;
            default:
                this.tableData = undefined;
                break;
        }
    }
}
